package com.course.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Vector;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.course.bean.CourseTo;
import com.course.delegate.CourseMgrDelegate;
import com.course.exception.DataNotFoundException;
import com.course.util.UtilConstants;



public class ViewMaterialAction extends HttpServlet {

	private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
                 doPost(request, response);
	}
public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String path="";
		Vector<CourseTo> materialInfo=null;

		  try{
			  
			  int cid=Integer.parseInt(request.getParameter("courseid"));
			  
			  String path1="/document";
			  try{
			  materialInfo= new CourseMgrDelegate().viewMaterial(path1,cid);				  								 
			  }catch (DataNotFoundException e) {
				e.printStackTrace();
			}
			  System.out.println("in Action class vcb..........."+materialInfo);
			  if(!materialInfo.isEmpty()){
				  request.setAttribute("MaterialInfo", materialInfo);
				  request.setAttribute("status", UtilConstants._MATERIAL_INFO);
		          path=UtilConstants._VIEW_MATERIAL_HOME;
				 }
			  else {
				  request.setAttribute("status", UtilConstants._NO_MATERIAL_INFO);
		          path=UtilConstants._VIEW_MATERIAL_HOME;
				}
			   }
		  catch (NullPointerException e) {
			  request.setAttribute("status", UtilConstants._INVALIED_DATA);
	          path=UtilConstants._VIEW_MATERIAL_HOME;
			e.printStackTrace();
			}
		RequestDispatcher rd=request.getRequestDispatcher(path);
			rd.forward(request,response);
	}

}
